﻿using System.Text;
using System.Web;
using System.Xml;

namespace AnOtherBlog.Core.HttpHandlers
{
	/// <summary>
	/// RSD (Really Simple Discoverability) Handler
	/// http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html
	/// </summary>
	public class RSD : IHttpHandler
	{
		#region IHttpHandler Members

		public bool IsReusable
		{
			get
			{
				return false;
			}
		}

		public void ProcessRequest(HttpContext context)
		{
			context.Response.ContentType = "text/xml";
			using (XmlTextWriter rsd = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8))
			{
				rsd.Formatting = Formatting.Indented;
				rsd.WriteStartDocument();
				// Rsd tag
				rsd.WriteStartElement("rsd");
				rsd.WriteAttributeString("version", "1.0");

				// Service 
				rsd.WriteStartElement("service");
				rsd.WriteElementString("engineName", "AnOtherBlog");
				rsd.WriteElementString("engineLink", "http://www.codeplex.com/anotherblog");
				rsd.WriteElementString("homePageLink", Util.WebRootAbsolute.ToString());

				// APIs
				rsd.WriteStartElement("apis");

				// MetaWeblog
				rsd.WriteStartElement("api");
				rsd.WriteAttributeString("name", "MetaWeblog");
				rsd.WriteAttributeString("preferred", "true");
				rsd.WriteAttributeString("apiLink", Util.WebRootAbsolute.ToString() + "metaweblogAPI.ashx");
				rsd.WriteAttributeString("blogID", "");
				rsd.WriteEndElement();

				// End APIs
				rsd.WriteEndElement();
				// End Service
				rsd.WriteEndElement();
				// End Rsd
				rsd.WriteEndElement();
				rsd.WriteEndDocument();
			}
		}

		#endregion
	}
}
